
package clases;

import javax.swing.JTextField;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;


public class TFnumericos extends PlainDocument{
    
  private JTextField miJTextField;
  private int nroMaxCaracteres;
  
    public TFnumericos(JTextField mijtext, int nroMaxCaract){
      miJTextField=mijtext;
      nroMaxCaracteres=nroMaxCaract;
  }

    @Override
 public void insertString(int arg0, String arg1, AttributeSet arg2) throws BadLocationException
 {
 
     for (int i=0;i<arg1.length();i++) {
         if (!Character.isDigit(arg1.charAt(i))||(miJTextField.getText().length()+arg1.length())>nroMaxCaracteres) {
             return;
         }
     }
         super.insertString(arg0, arg1, arg2);
 }
}

